<template>
    <input class='search' v-model='searchText' placeholder="Enter Hero Name">
    <div class='waterfall-container' @click='order = order *-1 | debounce '>
        <div class='waterfall-content' >
            <waterfall 
            :align="center" 
            :line='h' 
            :line-gap="115"
            :min-line-gap='115' 
            :max-line-gap='130' 
            :single-max-width="115" 
            :watch="items">
                <waterfall-slot 
                v-for="item in items | orderBy 'name' order | filterBy searchText in 'name' "
                :width="50" 
                :height="100" 
                move-class="item-move" 
                transition="wf" 
                track-by="$index">
                    <custom-comp>
                        <div class='waterfallslot' @click='showDetail(item.name)'>
                            <img class='hero-hover' :src="item.src" alt="">
                            <div class='icon-top'><img style='width:15px' src='../assets/overviewicon_str.png'></div>
                            <div class='text-bottom'>
                                <span v-text='item.name |  abbrivate'></span>
                            </div>
                        </div>
                    </custom-comp>
                </waterfall-slot>
            </waterfall>
        </div>
    </div>
</template>
<style scoped>
    .wf-transiton {
        transition: opacity .3s ease;
    }
    
    .wf-leave {
        opacity: 0;
    }
    
    .item-move {
        transition: all .5s cubic-bezier(.55, 0, .1, 1);
    }
    
    .icon-top {
        position: absolute;
        top: 0;
        left: 5px;
        z-index: 10;
    }
    
    .img-center {
        position: relative;
    }
    
    .text-bottom {
        position: absolute;
        top: 53px;
        color: #fff;
        text-align: center;
        width: 95px;
        height: 20px;
        background-color: rgba(0, 0, 0, 0.7);
        font-size: 10px;
    }
    
    .text-bottom:hover {}
    
    img.hero-hover {
        width: 95px;
        opacity: 0.7;
    }
    
    img.hero-hover:hover {
        opacity: 1;
    }
    
    .waterfallslot {
        position: relative;
        display: inline-block;
        top: 0;
        left: 0;
        width: 95px;
        height: 100px;
        cursor: pointer;
    }
    
    .waterfallslot:hover {}
    
    .waterfall-content {
        margin: 0 auto;
        padding: 20px 0;
    }
    
    .waterfall-container {
        padding: 0 200px;
        background-color: rgba(33, 33, 33, 1);
        min-height:605px;
    }
    .search{
        position:fixed;
        top:63px;
        left:10px;
        background-color:rgba(255, 255, 255, 0.2);
        padding: 2px 12px;
        color:rgba(255, 255, 255, 0.8);
        outline:0;
        border:0;
        width:150px;
        font-size:14px;
        height:30px;
        line-height:30px;
        border-radius:5px;
    }
</style>
<script>
    import Waterfall from 'vue-waterfall/lib/waterfall'
    import WaterfallSlot from 'vue-waterfall/lib/waterfall-slot'
    import CustomComp from './CustomComp.vue'
    import { item } from '../js/item.js'
    export default{
        data(){
            return {
                items:item.get(),
                sort:'asc',
                order:-1,
                searchText:''
            }
        },
        components:{
            Waterfall,
            WaterfallSlot,
            CustomComp,
        },
        methods:{
            showDetail(name){
                // 打开新窗口指向 英雄的详细界面.
                open().location.href = 'http://www.dotamax.com/hero/detail/' + name ;
                // open("about:blank").location.href = 'http://www.dotamax.com/hero/detail/' + name ;
            },
            // sort(){
            //     this.items.sort();
            // }
        },
        ready(){
            // $(window).on('click',()=>{
            //     if(this.sort=='asc'){
            //         this.items.sort(function(a,b){
            //             if(a.name<b.name){
            //                 return 1;
            //             }else{
            //                 return -1;
            //             }
            //         });
            //         this.sort = 'desc'
            //     }else{
            //         this.items.sort(function(a,b){
            //             if(a.name > b.name){
            //                 return 1;
            //             }else{
            //                 return -1;
            //             }
            //         });
            //         this.sort = 'asc'
            //     }
            // });
        },
        beforeDestroyed(){
            // $(window).off('click');
        }
    }
</script>